<html>
<head><meta charset="utf-8"><title>Modifying linker actions breaks incremental compilation. · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Modifying.20linker.20actions.20breaks.20incremental.20compilation.2E.html">Modifying linker actions breaks incremental compilation.</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="218838995"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Modifying%20linker%20actions%20breaks%20incremental%20compilation./near/218838995" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edd Barrett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Modifying.20linker.20actions.20breaks.20incremental.20compilation.2E.html#218838995">(Dec 04 2020 at 14:29)</a>:</h4>
<p>Hi,</p>
<p>I'm back with another odd question.</p>
<p>I need to get the compiler to add an ELF section to the binaries it is spitting out. Unfortunately the section needs to be derived from finalized DWARF data, so I can't simply generate an object file and add it to the linked objects: I need to inspect the "end binary" and change it.</p>
<p>(What on earth am I doing? This is an optimisation for our Rust meta-tracer.  I'm searching the DWARF data for special DILabel debuginfo entries and putting them in a quicker to load (at runtime) format).</p>
<p>My approach is as follows. Right after the linker has been executed (right at the end of <code>rustc_codegen_ssa::src::back::link::link_natively</code>):</p>
<ul>
<li>Walk the dwarf tree and copy the bits I want into a vector.</li>
<li>Use serde to serialise this vector into a temporary file.</li>
<li>Use objcopy to make a new binary including the serialised data in a new named section.</li>
<li>Move the new binary over the old one.</li>
</ul>
<p>(I know, I know... hacky)</p>
<p>To my surprise this mostly works. Why mostly? Well sometimes it breaks incremental compilation like this:</p>
<div class="codehilite"><pre><span></span><code>thread &#39;rustc&#39; panicked at &#39;called `Option::unwrap()` on a `None` value&#39;, compiler/rustc_middle/src/ty/query/mod.rs:244:5
stack backtrace:
   0: rust_begin_unwind
             at /home/vext01/research/yorick/ykrustc/library/std/src/panicking.rs:493:5
   1: core::panicking::panic_fmt
             at /home/vext01/research/yorick/ykrustc/library/core/src/panicking.rs:92:14
   2: core::panicking::panic
             at /home/vext01/research/yorick/ykrustc/library/core/src/panicking.rs:50:5
   3: rustc_middle::ty::query::try_load_from_on_disk_cache
   4: rustc_query_system::dep_graph::graph::DepGraph&lt;K&gt;::exec_cache_promotions
             at /home/vext01/research/yorick/ykrustc/compiler/rustc_query_system/src/dep_graph/graph.rs:818:21
...
  45: rustc_session::utils::&lt;impl rustc_session::session::Session&gt;::time
             at /home/vext01/research/yorick/ykrustc/compiler/rustc_session/src/utils.rs:9:9
  46: rustc_codegen_ssa::base::finalize_tcx
             at /home/vext01/research/yorick/ykrustc/compiler/rustc_codegen_ssa/src/base.rs:752:5
  47: rustc_codegen_ssa::base::codegen_crate
             at /home/vext01/research/yorick/ykrustc/compiler/rustc_codegen_ssa/src/base.rs:697:5
...
</code></pre></div>
<p>So it's upsetting the dependency caching system somehow. Through print debugging (the backtrace isn't very detailed, presumably due to macro fun), it looks like something in <code>DepNodeParams::recover()</code>.</p>
<p>But I'm kind of confused as to why this is problematic. Rustc is expecting a file to appear out of the ether when it runs the linker. So why does it matter if the binary has my new section appended or not? Any ideas?</p>



<a name="218848091"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Modifying%20linker%20actions%20breaks%20incremental%20compilation./near/218848091" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Modifying.20linker.20actions.20breaks.20incremental.20compilation.2E.html#218848091">(Dec 04 2020 at 15:35)</a>:</h4>
<p>That seems to be <a href="https://github.com/rust-lang/rust/issues/79661">#79661</a>. Could you post your analysis of what happens there?</p>



<a name="218848110"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Modifying%20linker%20actions%20breaks%20incremental%20compilation./near/218848110" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Modifying.20linker.20actions.20breaks.20incremental.20compilation.2E.html#218848110">(Dec 04 2020 at 15:35)</a>:</h4>
<p><span class="user-mention" data-user-id="223288">@Edd Barrett</span> ^</p>



<a name="218849207"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Modifying%20linker%20actions%20breaks%20incremental%20compilation./near/218849207" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edd Barrett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Modifying.20linker.20actions.20breaks.20incremental.20compilation.2E.html#218849207">(Dec 04 2020 at 15:43)</a>:</h4>
<p>Oh! So maybe this has nothing to do with my change at all! I'm going to see if I can reproduce it without.</p>



<a name="218849986"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Modifying%20linker%20actions%20breaks%20incremental%20compilation./near/218849986" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edd Barrett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Modifying.20linker.20actions.20breaks.20incremental.20compilation.2E.html#218849986">(Dec 04 2020 at 15:48)</a>:</h4>
<p>Yep, nothing to do with my change.</p>



<a name="218850011"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Modifying%20linker%20actions%20breaks%20incremental%20compilation./near/218850011" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edd Barrett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Modifying.20linker.20actions.20breaks.20incremental.20compilation.2E.html#218850011">(Dec 04 2020 at 15:48)</a>:</h4>
<p>Thanks for pointing this out <span class="user-mention" data-user-id="133247">@bjorn3</span></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>